/**
 * Copyright 2011 By Shayne, Zhang.
 * 
 * The contents of this file are developped by Shayne, Zhang. You may visit:
 * http://www.shaynez.com for more details.
 *
 */
package com.shaynez.ec.element;

import com.shaynez.ec.Constants;
import com.shaynez.ec.exception.InvalidateValueException;

/**
 * shutter value means 1/value second
 * 
 * @author shayne zhang
 *
 */
public class Shutter implements Calculatable<Shutter>, ExposureElement {
	private double value;
	
	protected Shutter(double value){
		this.value = value;
	}
	
	public static Shutter getInstance(double value) throws InvalidateValueException{
		if(value < Constants.THE_MIN_SENSITIVITY_VALUE || value > Constants.THE_MAX_SENSITIVITY_VALUE){
			throw new InvalidateValueException("Invalidate Shutter value > " + value);
		}
		return new Shutter(value);
	}
	
	@Override
	public double getValue(){
		return value;
	}

	@Override
	public double getExposureValue() {
		// TODO Auto-generated method stub
		return 1 / value;
	}

	@Override
	public double getValueByExposureValue(double exposureValue) {
		// TODO Auto-generated method stub
		return 1 / exposureValue;
	}

	@Override
	public Shutter calculate(Factor factor) throws InvalidateValueException {
		// TODO Auto-generated method stub
		return Shutter.getInstance(this.getValueByExposureValue(this.getExposureValue() / factor.getValue()));
	}
	
	@Override
	public Factor compare(Shutter o) {
		// TODO Auto-generated method stub
		return new Factor(o.getExposureValue() / this.getExposureValue());
	}
}
